<?php

namespace Home\Controller;

/**
 * 引导页controller
 * @modify trainyao 2016-01-04 创建
 */
class GuidancePageController extends \Home\Controller\ParentController {
    protected $tableName = 'guidancetable';

    protected function _initialize() {
        $this->guiRedisUtil = new \Org\Util\RedisHelper(null, null, 'meizhu');
        $this->guiRedisUtil->db(C('REDIS_ORDER_PUSH_DB'))->table($this->tableName);
        $this->validateUtil = new \Org\Util\Validate();
    }

    /**
     * 获取引导页
     * @modify wenhui 2017-11-20    创建
     */
    public function getGuidanceData() {
        $param = I('post.');

        $validateRule = array(
            'guidances' => 'notnull,notempty',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        $userId = getUserId();
        $guidanceArray = $param['guidances'];

        if (!is_array($guidanceArray)) {
            $guidanceArray = explode(',', $guidanceArray);
        }

        $guidanceData = $this->guiRedisUtil->hMGet($userId);
        $returnData = array();
        foreach ($guidanceArray as $key => &$guidance) {
            $returnData[$guidance] = isset($guidanceData[$guidance]) ? false : true;
        }

        returnJson(200, 200, $returnData);
    }

    /**
     * 获取引导页
     * @modify wenhui 2017-11-20    创建
     */
    public function setGuidanceData() {
        $param = I('post.');

        $validateRule = array(
            'guidances' => 'notnull,notempty',
        );
        $validatePass = $this->ajaxValidateReturn($this->validateUtil, $param, $validateRule);
        if (empty($validatePass)) {
            return;
        }

        $userId = getUserId();
        $guidance = $param['guidances'];
        $addResutl = $this->guiRedisUtil->hMSet($userId, [$guidance => 1]);

        returnJson(200, 200);
    }
}
